package cn.classTest.mall.controller;

import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.RoleService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.management.relation.Role;
import java.util.List;

@Controller
@RequestMapping("role")
public class RoleController {
    @Autowired
    private RoleService roleServiceImpl;

    @RequiresPermissions(value = {"role:list","角色列表"},logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, QueryObject qo){
        PageInfo<Role> pageInfo = roleServiceImpl.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/role/list";
    }

    @RequiresPermissions(value = {"{role:input","角色输入"},logical = Logical.OR)
    @RequestMapping("/input")
    public String input(Model model,Long id){
        if(id != null){
            Role role = roleServiceImpl.selectOne(id);
            model.addAttribute("role",role);
        }
        List<Permission> permissions = permissionServiceImpl.selectAll();
        model.addAttribute("permissions", permissions);
        return "/role/input";
    }
}
